home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 April / PCWorld_2008-04_cd.bin / domacnost a kancelar / ubericon / UberIcon-v1.0.3.exe / {app} / Plugins / iZoom / Source / iZoom.cpp next >
C/C++ Source or Header  |  2006-03-12  |  12KB  |  320 lines

  1. // iZoom.cpp
  2. // ---------------------------------------------------------------------------------
  3. // iZoom was created as an example of the ▄berIcon plugin system.  Until we finalize
  4. // the plugin system and properly document it, this example will be your gateway to
  5. // writing you r own plugins for ▄berIcon.
  6.  
  7. // Some important things to note:
  8. // An option's Group and Name will ALWAYS be passed thru the translation engine
  9. // for the user interface.  This has no effect from the plugin's point-of-view, but
  10. // you should ALWAYS try to use words/phrases that have ALREADY BEEN TRANSLATED
  11. // to ensure that people from all over the world can understand your options.
  12. // To find words that are already translated, look in your language's ini file
  13. // (english="Languages\1033.ini")
  14.  
  15. // If you're adding a group or option that has not been translated, feel free to
  16. // write it out as more than one word (eg "my option").  Our translation system can
  17. // easily handle translating this later on.  We stick to single-words for easier
  18. // development...
  19.  
  20. // If you're adding a custom window/interface for your options, remember to use the
  21. // Uber_Translate() function to translate text to display.  the string you pass MUST
  22. // be MAX_PATH characters long to avoid buffer overflows. Remember that "Bonjour" is
  23. // longer than "Hello" :)
  24. //
  25. // Example:
  26. // wchar_t text[MAX_PATH]=L"Hello";
  27. // Uber_Translate(text);//text is now "Bonjour"...
  28.  
  29. // More about the Options System:
  30. // Each Option has 4 properties.
  31. // 1) Group        -> The name of the option's logical group
  32. // 2) Name        -> The name of the option
  33. // 3) Value        -> A UINT value that is remembered for you...
  34. // 4) sValue    -> A string value that is remembered for you...
  35. //
  36. // The Option GroupModes act as follows:
  37. // UBER_GROUPMODE_NORMAL    ->    Normal option...
  38. // UBER_GROUPMODE_HIDDEN    ->    Invisible option (simply used for storing info)...
  39. // UBER_GROUPMODE_CHECKBOX  ->    Similar to NORMAL, only a Checkbox is shown next to
  40. //                                Options with a non-zero value.
  41. // UBER_GROUPMODE_RADIO        ->    Similar to CHECKBOX, only when you set an option's
  42. //                                value, all other options in the group reset to 0
  43. //
  44. // ALL MODES call your OptionSelected() procedure
  45. // ---------------------------------------------------------------------------------
  46.  
  47. #include "stdafx.h"
  48. #include "../../../UberAPI/UberAPI.h"
  49.  
  50.  
  51. LRESULT CALLBACK IconProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  52. VOID CALLBACK IconTimerProc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
  53.  
  54. Gdiplus::GdiplusStartupInput gdiplusStartupInput;
  55. ULONG_PTR  gdiplusToken;
  56.  
  57. BOOL APIENTRY DllMain( HANDLE hModule, 
  58.                        DWORD  ul_reason_for_call, 
  59.                        LPVOID lpReserved
  60.                      )
  61. {
  62.  
  63.     switch(ul_reason_for_call)
  64.     {
  65.     case DLL_PROCESS_ATTACH://Init
  66.         {
  67.             //Plugin Info (Automatically Hidden)
  68.             Uber_AddOption(L"PluginInfo", L"Name", 0, L"iZoom");//Overrides the display name of the Plugin :)
  69.             Uber_AddOption(L"PluginInfo", L"Version", 0, L"1.0");//Might be used in the future
  70.             Uber_AddOption(L"PluginInfo", L"Author", 0, L"PolyVector");//Might be used in the future
  71.             Uber_AddOption(L"PluginInfo", L"URL", 0, L"www.punksoftware.com");//Might be used in the future
  72.             Uber_AddOption(L"PluginInfo", L"Contact", 0, L"support@punksoftware.com");//Might be used in the future
  73.  
  74.             //Options for the user
  75.             Uber_SetOptionGroupMode(L"PluginSettings", UBER_GROUPMODE_CHECKBOX);
  76.             Uber_AddOption(L"PluginSettings", L"Echo", false, L"");
  77.             Uber_AddOption(L"PluginSettings", L"Outline", false, L"");
  78.             Uber_AddOption(L"PluginSettings", L"Async", false, L"");
  79.  
  80.             Uber_AddOption(L"", L"AboutPlugin", 0, L"");
  81.  
  82.  
  83.             //The following is a demonstration of the HIDDEN GroupType...
  84.             //The Option "FirstTime" is created in a hidden group and
  85.             //is set to 'true' by default...
  86.             //After the plugin is run for the first time it's set to false
  87.             Uber_SetOptionGroupMode(L"Hidden", UBER_GROUPMODE_HIDDEN);
  88.             Uber_AddOption(L"Hidden",L"FirstTime",true,L"");
  89.             if(Uber_GetOption(L"Hidden",L"FirstTime"))
  90.             {
  91.                 //MessageBox(0,L"This is the first time this plugin has been loaded",L"Notice",0);
  92.                 Uber_SetOption(L"Hidden",L"FirstTime",false);
  93.             }
  94.             
  95.  
  96.             //Icon Zoomer Class
  97.             WNDCLASSEX wcex;
  98.             wcex.cbSize = sizeof(WNDCLASSEX); 
  99.             wcex.style            = CS_HREDRAW | CS_VREDRAW;
  100.             wcex.lpfnWndProc    = (WNDPROC)IconProc;
  101.             wcex.cbClsExtra        = 0;
  102.             wcex.cbWndExtra        = 0;
  103.             wcex.hInstance        = NULL;
  104.             wcex.hIcon            = NULL;
  105.             wcex.hCursor        = NULL;
  106.             wcex.hbrBackground    = NULL;
  107.             wcex.lpszMenuName    = _T("");
  108.             wcex.lpszClassName    = _T("iZoomWnd");
  109.             wcex.hIconSm        = NULL;
  110.             RegisterClassEx(&wcex);
  111.  
  112.             // Initialize Gdiplus
  113.             GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
  114.  
  115.         }
  116.  
  117.         break;
  118.     case DLL_PROCESS_DETACH://Exit
  119.         //MessageBox(0,L"Plugin Exit",L"",0);
  120.  
  121.         // Shutodwn Gdiplus
  122.         Gdiplus::GdiplusShutdown(gdiplusToken);
  123.         break;
  124.     }
  125.     return TRUE;
  126. }
  127.  
  128. //OptionSelected()
  129. //-------------------------------------------------------
  130. //This function is called when an UBER_GROUPMODE_CALLBACK
  131. //Option is clicked on.
  132. //-------------------------------------------------------
  133. bool UBERFUNCTION OptionSelected(wchar_t* Group, wchar_t* Name)
  134. {
  135.     //MessageBox(0,Name,Group,0);
  136.     if(!wcscmp(Group,L""))
  137.     {
  138.         if(!wcscmp(Name,L"AboutPlugin"))
  139.         {
  140.             wchar_t About[MAX_PATH]=L"AboutPlugin";
  141.             Uber_Translate(About);
  142.             MessageBox(0,L"iZoom was created by PunkSoftware\n\nIf you are interested in developing Effects\nlook in the 'Plugins' folder for sourcecode.",About,0);
  143.         }
  144.     }
  145.     return true;
  146. }
  147.  
  148. //ActivateIcon()
  149. //---------------------------------------------------------
  150. //This function gets called each time an Icon is Activated
  151. //Simply start your ⁿber cool special effect here :)
  152. //Icon execution is blocked until this function returns
  153. //
  154. //A simple SetTimer() or CreateThread() call will allow for
  155. //async special effects :)
  156. //---------------------------------------------------------
  157. bool UBERFUNCTION ActivateIcon(UBER_ICON* data)
  158. {
  159.     //IMPORTANT NOTES:
  160.     //Create the window invisible and later show it with SW_SHOWNOACTIVATE
  161.     //This will prevent focus from leaving the current window.
  162.     //Using WS_EX_TRANSPARENT will prevent users clicking on the effect's window
  163.     HWND hWnd=CreateWindowEx(WS_EX_TOPMOST| WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW, _T("iZoomWnd"), _T(""), WS_POPUP | WS_CLIPSIBLINGS, 0, 0, 64, 64, NULL, NULL, NULL, NULL);
  164.     ShowWindow(hWnd,SW_SHOWNOACTIVATE);
  165.  
  166.  
  167.     Gdiplus::Bitmap* IconBitmapCopy=NULL;
  168.  
  169.     //Creates a Bitmap of the Outline of the Icon
  170.     if(Uber_GetOption(L"PluginSettings", L"Outline"))
  171.     {
  172.         IconBitmapCopy=new Gdiplus::Bitmap(data->bitmap->GetWidth(),data->bitmap->GetHeight(),PixelFormat32bppARGB);
  173.         int width=data->bitmap->GetWidth();
  174.         int height=data->bitmap->GetHeight();
  175.         for(int y=0;y<height;y++)
  176.         {
  177.             for(int x=0;x<width;x++)
  178.             {
  179.                 Gdiplus::Color cMid;
  180.                 data->bitmap->GetPixel(x,y,&cMid);
  181.                 if(cMid.GetAlpha())
  182.                 {
  183.                     if(x==0||y==0||x==width-1||y==height-1)
  184.                         IconBitmapCopy->SetPixel(x,y,Color(255,0,0,0));
  185.                     else
  186.                     {
  187.                         Gdiplus::Color cLeft,cTop,cRight,cBottom;
  188.                         data->bitmap->GetPixel(x-1,y,&cLeft);
  189.                         data->bitmap->GetPixel(x,y-1,&cTop);
  190.                         data->bitmap->GetPixel(x+1,y,&cRight);
  191.                         data->bitmap->GetPixel(x,y+1,&cBottom);
  192.                         if(!cLeft.GetAlpha()||!cTop.GetAlpha()||!cRight.GetAlpha()||!cBottom.GetAlpha())
  193.                             IconBitmapCopy->SetPixel(x,y,Color(255,0,0,0));
  194.                     }
  195.                 }
  196.  
  197.  
  198.             }
  199.         }
  200.  
  201.     }
  202.     else
  203.     {
  204.         IconBitmapCopy=data->bitmap->Clone(0,0,data->bitmap->GetWidth(),data->bitmap->GetHeight(),PixelFormat32bppARGB);
  205.     }
  206.  
  207.     SetProp(hWnd,_T("IcoBmp"),(HANDLE)IconBitmapCopy);
  208.     RECT ItemRect=data->rect;
  209.     SetProp(hWnd,_T("midX"),(HANDLE)((ItemRect.right+ItemRect.left)/2));//MiddleX
  210.     SetProp(hWnd,_T("midY"),(HANDLE)((ItemRect.bottom+ItemRect.top)/2));//MiddleY
  211.     int minSize=(ItemRect.bottom-ItemRect.top);
  212.     SetProp(hWnd,_T("minSize"),(HANDLE)minSize);//MiddleY
  213.     int SysIconSize=GetSystemMetrics(SM_CXICON);
  214.     int maxSize=SysIconSize*8;
  215.     if(maxSize<minSize+(SysIconSize*2))
  216.         maxSize=minSize+(SysIconSize*2);
  217.     SetProp(hWnd,_T("maxSize"),(HANDLE)maxSize);//MiddleY
  218.     SetProp(hWnd,_T("ms"),(HANDLE)0);
  219.  
  220.     if(Uber_GetOption(L"PluginSettings", L"Async"))
  221.     {
  222.         //animate fx while loading (sometimes ugly)
  223.         SetTimer(hWnd,NULL,1000/75,IconTimerProc);
  224.     }
  225.     else
  226.     {
  227.         //Wait for fx to finish before continuing (smoooooth)
  228.         while(IsWindow(hWnd))
  229.             IconTimerProc(hWnd,0,0,0);
  230.     }
  231.     return true;
  232. }
  233.  
  234. LRESULT CALLBACK IconProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  235. {
  236.     return DefWindowProc(hWnd,message,wParam,lParam);
  237. }
  238.  
  239. VOID CALLBACK IconTimerProc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
  240. {
  241.             int OldMS=(int)GetProp(hWnd,_T("ms"));
  242.             if(!OldMS)
  243.             {
  244.                 OldMS=GetTickCount();
  245.                 SetProp(hWnd,_T("ms"),(HANDLE)OldMS);
  246.             }
  247.             int NewMS=GetTickCount();
  248.             Gdiplus::Bitmap* IconBitmap=(Gdiplus::Bitmap*)GetProp(hWnd,_T("IcoBmp"));
  249.             if(IconBitmap)
  250.             {
  251.                 int MinSize=(int)GetProp(hWnd,_T("minSize"));
  252.                 int MaxSize=(int)GetProp(hWnd,_T("maxSize"));
  253.                 int IconSize=MinSize+int(float(NewMS-OldMS)/200.0f * (MaxSize-MinSize));
  254.                 float alpha=(float(MaxSize-IconSize)/float(MaxSize-MinSize));
  255.                 alpha*=0.55f;
  256.                 if(alpha<0.0f)
  257.                     alpha=0.0f;
  258.                 POINT WindowOrg;
  259.                 WindowOrg.x=(int)GetProp(hWnd,_T("midX"))-(IconSize/2);
  260.                 WindowOrg.y=(int)GetProp(hWnd,_T("midY"))-(IconSize/2);
  261.                 
  262.                 //Setup Buffer
  263.                 HBITMAP BufferBM;
  264.                 HDC BufferDC;
  265.                 BITMAPINFO BufferBMInfo;
  266.                 ZeroMemory(&BufferBMInfo,sizeof(BITMAPINFO));
  267.                 BufferBMInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
  268.                 BufferBMInfo.bmiHeader.biWidth=IconSize;
  269.                 BufferBMInfo.bmiHeader.biHeight=IconSize;
  270.                 BufferBMInfo.bmiHeader.biPlanes=1;
  271.                 BufferBMInfo.bmiHeader.biBitCount=32;
  272.                 BufferDC=CreateCompatibleDC(NULL);
  273.                 BufferBM=CreateDIBSection(BufferDC,&BufferBMInfo,DIB_RGB_COLORS,NULL,NULL,NULL);
  274.                 SelectObject(BufferDC,BufferBM);
  275.                 Gdiplus::Graphics graphics(BufferDC);
  276.                 graphics.SetCompositingMode(CompositingModeSourceCopy);
  277.                 graphics.SetCompositingQuality(CompositingQualityHighSpeed);
  278.                 graphics.SetInterpolationMode(InterpolationModeBilinear);
  279.  
  280.                 //Start Rendering
  281.                 int TrailCount=1;
  282.                 if(Uber_GetOption(L"PluginSettings", L"Echo"))
  283.                     TrailCount=5;
  284.                 int IconSizeOffset=0;
  285.                 for(float i=0;i<TrailCount;i++)
  286.                 {
  287.                     IconSizeOffset=((IconSize-IconBitmap->GetWidth())/TrailCount)*(i);
  288.                     graphics.DrawImage(    IconBitmap,
  289.                         Gdiplus::Rect(IconSizeOffset/2,IconSizeOffset/2,IconSize-IconSizeOffset,IconSize-IconSizeOffset),
  290.                         0,
  291.                         0,
  292.                         IconBitmap->GetWidth(),
  293.                         IconBitmap->GetHeight(),
  294.                         Gdiplus::UnitPixel,
  295.                         NULL);
  296.                     graphics.SetCompositingMode(CompositingModeSourceOver);
  297.                 }
  298.  
  299.                 SIZE BufferSize={IconSize,IconSize};
  300.                 POINT SrcOrg={0,0};
  301.                 BLENDFUNCTION Blend;
  302.                 Blend.BlendOp=AC_SRC_OVER;
  303.                 Blend.BlendFlags=0;
  304.                 Blend.SourceConstantAlpha=BYTE(255*alpha);
  305.                 Blend.AlphaFormat=AC_SRC_ALPHA;
  306.  
  307.                 UpdateLayeredWindow(hWnd,0,&WindowOrg,&BufferSize,BufferDC,&SrcOrg,RGB(0,0,0),&Blend,ULW_ALPHA);
  308.  
  309.                 DeleteDC(BufferDC);
  310.                 DeleteObject(BufferBM);
  311.                 if(alpha==0.0f)
  312.                 {
  313.                     KillTimer(hWnd,NULL);
  314.                     ShowWindow(hWnd,SW_HIDE);
  315.                     DestroyWindow(hWnd);
  316.                     SetProp(hWnd,_T("IcoBmp"),NULL);
  317.                     delete IconBitmap;
  318.                 }
  319.             }
  320. }